﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Neo4JConnector.Semantic
{
    public interface IVectorIndex
    {
        /// <summary>
        /// 添加向量到索引
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <param name="vector">向量</param>
        void Add(string id, float[] vector);

        /// <summary>
        /// 更新索引中的向量
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <param name="vector">新向量</param>
        void Update(string id, float[] vector);

        /// <summary>
        /// 从索引中移除向量
        /// </summary>
        /// <param name="id">实体ID</param>
        void Remove(string id);

        /// <summary>
        /// 尝试获取向量
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <param name="vector">输出向量</param>
        /// <returns>是否成功获取</returns>
        bool TryGetVector(string id, out float[] vector);

        /// <summary>
        /// 搜索最相似的向量
        /// </summary>
        /// <param name="queryVector">查询向量</param>
        /// <param name="topK">返回结果数量</param>
        /// <returns>相似向量结果</returns>
        List<VectorResult> Search(float[] queryVector, int topK);

        /// <summary>
        /// 批量添加向量
        /// </summary>
        /// <param name="label">标签/类别</param>
        /// <param name="vectors">向量记录列表</param>
        void BulkAdd(string label, List<VectorRecord> vectors);

        /// <summary>
        /// 创建索引
        /// </summary>
        /// <param name="label">标签/类别</param>
        void CreateIndex(string label);

        /// <summary>
        /// 删除索引
        /// </summary>
        /// <param name="label">标签/类别</param>
        void DeleteIndex(string label);

        /// <summary>
        /// 获取索引中的向量数量
        /// </summary>
        /// <param name="label">标签/类别</param>
        /// <returns>向量数量</returns>
        int Count(string label);
    }

    /// <summary>
    /// 向量搜索结果
    /// </summary>
    public class VectorResult
    {
        public string Id { get; set; }
        public float Distance { get; set; }

        public VectorResult(string id, float distance)
        {
            Id = id;
            Distance = distance;
        }
    }

    /// <summary>
    /// 向量记录
    /// </summary>
    public class VectorRecord
    {
        public string Id { get; set; }
        public float[] Vector { get; set; }

        public VectorRecord(string id, float[] vector)
        {
            Id = id;
            Vector = vector;
        }
    }
}
